import javax.swing.*;
import java.awt.*;

public class CanvasExample extends JPanel {
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;

        // 设置颜色为蓝色
        g2d.setColor(Color.BLUE);
        // 绘制矩形
        g2d.fillRect(50, 50, 100, 100);

        // 设置颜色为红色
        g2d.setColor(Color.RED);
        // 绘制圆形
        g2d.fillOval(200, 50, 100, 100);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Canvas Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new CanvasExample());
        frame.setSize(400, 200);
        frame.setVisible(true);
    }
}